package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.Department;
import com.woniu.supermarket.mapper.DepartmentMapper;
import com.woniu.supermarket.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public int addDepartment(Department department) {
        return departmentMapper.insert(department);
    }

    @Override
    public int modifyDepartment(Department department) {
        return departmentMapper.updateByPrimaryKey(department);
    }

    @Override
    public int removeDepartment(Integer id) {
        return departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<Department> findByConds(Integer now, Integer size, String name) {
        PageHelper.startPage(now,size);
        List<Department> lists = departmentMapper.selectByConds(name);
        return new PageInfo<>(lists);
    }

    @Override
    public List<Department> findAll() {
        return departmentMapper.selectAll();
    }
}
